package com.bestcem.xm.member.mq.receiver;//package com.bestcem.xm.member.mq.receiver;
//
//import com.alibaba.fastjson.JSON;
//import com.bestcem.xm.config.RabbitMqConstant;
//import com.bestcem.xm.member.mq.message.SourceCardMessage;
//import com.bestcem.xm.member.mq.message.SyncRuleCacheMessage;
//import com.bestcem.xm.member.service.DisplayRangeService;
//import com.bestcem.xm.member.service.SourceCardService;
//import com.bestcem.xm.member.service.SyncRuleService;
//import com.bestcem.xm.util.MsgPackFormatUtil;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.Base64;
//
///**
// * 联系人 本地缓存队列监听
// *
// * @author yf.wang <yf.wang@idiaoyan.com>
// * @version V1.0
// * @date 2021/11/22
// */
//@Slf4j
//@Component
//public class MemberDbReceiver {
//
//    @Resource
//    private SourceCardService sourceCardService;
//
//    @RabbitListener(queues = "#{memberDbQueue.name}", ackMode = "MANUAL",
//            concurrency = "${app.member.db-config.receiver-consume-concurrency:10}",
//            containerFactory = "memberDbContainerFactory")
//    @RabbitHandler
//    public void handlerApp(Message message, Channel channel) {
//        try {
//            MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(message.getBody());
//            if (mqMessage == null) {
//                log.error("【member localCache】app消费mq消息解析失败:" + Base64.getEncoder().encodeToString(message.getBody()));
//                channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//                return;
//            }
//            if (log.isInfoEnabled()) {
//                log.info("【member localCache】app消费mq消息收到消息:{}", JSON.toJSONString(mqMessage));
//            }
//
//            if ("member.source_card_save".equals(mqMessage.getTopic())) {
//                SourceCardMessage sourceCardMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(), SourceCardMessage.class);
//                sourceCardService.handleSourceCard(sourceCardMessage);
//            }
//
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            log.error("【member localCache】处理倍市得app的mq消息异常:{}" + Base64.getEncoder().encodeToString(message.getBody()), e);
//            try {
//                channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//            } catch (Exception e2) {
//                log.error("【member localCache】处理倍市得app的mq消息, nackmq消息异常", e2);
//            }
//        }
//    }
//}
